package main

import "fmt"

type Usb interface {
	Start()
	Stop()
}

type Phone struct {
}

func (p Phone) Start() {
	fmt.Println("phone start...")
}

func (p Phone) Stop() {
	fmt.Println("phone stop....")
}

func (p Phone) Call() {
	fmt.Println("phone call....")
}

type Cramer struct {
}

func (p Cramer) Start() {
	fmt.Println("Cramer start...")
}

func (p Cramer) Stop() {
	fmt.Println("Cramer stop....")
}

type Computer struct {
}

//实现了某一个接口，就是实现该接口的所有方法
//实现了Usb接口，就是结构体实现Start和Stop方法
func (c Computer) Working(usb Usb) {
	usb.Start()
	usb.Stop()
}

//断言/向下转型
func main() {
	var usb Usb
	usb = Phone{}

	var phone Phone = Phone{}
	//向下转型，
	phone2 := usb.(Phone)
	phone2.Call()
	phone.Call()

	var infac interface{}
	var flo float64 = 1.2
	infac = flo

	//向下转型：格式-接口.(需要想强转的类型)
	if f, ok := infac.(float32); ok {
		fmt.Println("convert success")
		fmt.Println("f type %T", f)
	}
	fmt.Println("继续执行")
}
